<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:org:add']"
          >新增会员单位</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:org:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-upload2"
          size="mini"
          :disabled="single"
          @click="openInputDig"
          v-hasPermi="['system:org:grow']"
          >导入会员</el-button
        >
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:org:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-money"
          size="mini"
          @click="clickPayFee"
          v-hasPermi="['system:org:pay']"
          >缴费</el-button
        >
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :disabled="single"
          @click="setProxyAccount"
          v-hasPermi="['system:org:grow']"
          >设置成特殊帐号</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:org:remove']"
          >删除</el-button
        >
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="orgList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="机构名称" align="center" prop="memberOrgName" />

      <el-table-column label="审核状态" align="center" prop="memberOrgState">
        <template slot-scope="scope">
          <el-tag type="info" v-if="scope.row.memberOrgState === 0"
            >未知</el-tag
          >
          <el-tag type="success" v-if="scope.row.memberOrgState === 1"
            >是</el-tag
          >
          <el-tag type="danger" v-if="scope.row.memberOrgState === 2"
            >否</el-tag
          >
          <el-tag type="danger" v-if="scope.row.memberOrgState === null"
            >否</el-tag
          >

          <!-- <el-switch v-model="scope.row.memberOrgState" active-value="1"
    inactive-value="2"
    active-color="#13ce66"
    inactive-color="#ff4949"
    :change="changememberOrgState"
    >


          </el-switch> -->
        </template>
      </el-table-column>

      <el-table-column label="是否是专业机构" align="center" prop="isPro">
        <template slot-scope="scope">
          <el-tag type="info" v-if="scope.row.isPro === 0">未知</el-tag>
          <el-tag type="success" v-if="scope.row.isPro === 1">是</el-tag>
          <el-tag type="danger" v-if="scope.row.isPro === 2">否</el-tag>
          <el-tag type="danger" v-if="scope.row.isPro === null">否</el-tag>
        </template>
      </el-table-column>
      <!-- <el-table-column
        label="支付时间"
        align="center"
        prop="memberOrgPayTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.memberOrgPayTime, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="旗下会员" align="center" prop="membersNum">
        <template slot-scope="scope">
          <span v-if="scope.row.membersNum > 0 && scope.row.membersNum <= 10">
            <i class="el-icon-user-solid"></i>
          </span>
          <span v-if="scope.row.membersNum > 10 && scope.row.membersNum <= 20">
            <i class="el-icon-user-solid"></i><i class="el-icon-user-solid"></i>
          </span>
          <span v-if="scope.row.membersNum > 20 && scope.row.membersNum <= 30">
            <i class="el-icon-user-solid"></i><i class="el-icon-user-solid"></i
            ><i class="el-icon-user-solid"></i>
          </span>
          <span v-if="scope.row.membersNum > 30 && scope.row.membersNum <= 40">
            <i class="el-icon-user-solid"></i><i class="el-icon-user-solid"></i
            ><i class="el-icon-user-solid"></i>
          </span>
          <span v-if="scope.row.membersNum > 40 && scope.row.membersNum <= 50">
            <i class="el-icon-user-solid"></i><i class="el-icon-user-solid"></i
            ><i class="el-icon-user-solid"></i
            ><i class="el-icon-user-solid"></i>
          </span>
          <span v-if="scope.row.membersNum > 50">
            <i class="el-icon-user-solid"></i><i class="el-icon-user-solid"></i
            ><i class="el-icon-user-solid"></i
            ><i class="el-icon-user-solid"></i>
            <i class="el-icon-user-solid"></i><i class="el-icon-more"></i>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="所在城市" align="center" prop="city" />

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:org:edit']"
            >详情</el-button
          > -->

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:org:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:org:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改会员单位对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1000px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="机构名称" prop="memberOrgName">
              <el-input
                v-model="form.memberOrgName"
                placeholder="请输入机构名称"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法人" prop="memberOrgManager">
              <el-input
                v-model="form.memberOrgManager"
                placeholder="请输入法人"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="组织机构代码" prop="memberOrgSn">
              <el-input
                v-model="form.memberOrgSn"
                placeholder="请输入组织机构代码"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系方式" prop="memberOrgTel">
              <el-input
                v-model="form.memberOrgTel"
                placeholder="请输入联系方式"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="登录名" prop="memberOrgUsername">
              <el-input v-model="form.memberOrgUsername" placeholder="登录名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="登录密码" prop="memberOrgPassword">
              <el-input
                v-model="form.memberOrgPassword"
                show-password
                placeholder="请输入机构密码"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否是专业机构" prop="isPro">
              <el-switch
                v-model="form.isPro"
                active-color="#13ce66"
                inactive-color="#ff4949"
                active-value="1"
                inactive-value="2"
              >
              </el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所在城市" prop="address">
              <el-select v-model="form.city" placeholder="请选择">
                <el-option
                  v-for="item in cityList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="备注信息" prop="prop">
          <el-input v-model="form.prop" placeholder="请输入备注信息" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="导入" :visible.sync="inputMemberSync">
      <el-row type="flex" justify="center" :gutter="20">
        <el-col :span="12">

       <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport+'&orgId='+6"
        :disabled="upload.isUploading"


        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
            </div>
      </el-upload>

        </el-col>
        <!-- <el-col :span="12">
          <div class="downModel" @click="downModelFile">


            <label for="downButton" aria-hidden="true"
              ><p class="downText" >点击此处下载模版文件</p></label
            >

          </div>
        </el-col> -->
      </el-row>
        <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="inputMemberSync = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="缴费" :visible.sync="payFeeDig">
      <el-row type="flex" justify="center" :gutter="20">
        <el-col :span="12">
          <el-card>
            <div slot="header" class="clearfix">
              <span>给已选机构缴费</span>
              <el-button style="float: right; padding: 3px 0" type="text"
                >详情</el-button
              >
            </div>
            <el-row>
              <el-col>已选择单位：</el-col>
            </el-row>
            <el-row>
              <el-col v-for="item in payOrgList" :key="item.id">{{item.memberOrgName}}</el-col>
            </el-row>
            <el-row>
              <el-col>费用：</el-col>
            </el-row>
             <el-row>
              <el-col>{{OrgPrice}}</el-col>
            </el-row>
          </el-card>
        </el-col>
        <el-col :span="12">
          <el-card>
            <div slot="header" class="clearfix">
              <span>给已选机构的会员缴费</span>
              <el-button style="float: right; padding: 3px 0" type="text"
                >详情</el-button
              >
            </div>
            <div>1</div>
          </el-card>
        </el-col>
      </el-row>
    </el-dialog>

  </div>
</template>

<script>
// Import Vue FilePond
import vueFilePond from "vue-filepond";

// Import FilePond styles
import "filepond/dist/filepond.min.css";

// Import FilePond plugins
// Please note that you need to install these plugins separately

// Create component
const FilePond = vueFilePond();
import {
  listOrg,
  getOrg,
  delOrg,
  addOrg,
  updateOrg,
  grow,
  fee,
  downloadTemplate
} from "@/api/hnsdsa/memberorg/org";
import { getToken } from "@/utils/auth";

export default {
  components: {
    FilePond,
  },
  name: "Org",
  data() {
    return {
        // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/org/importMembers"
      },
      payOrgList:[],
      OrgPrice:0,
      payFeeDig: false,
      fileLabelIdle: "点此处上传会员文件",
      inputMemberSync: false,
      fileList: [],
      cityList: [
        { value: "郑州市", label: "郑州市" },
        { value: "开封", label: "开封" },
        { value: "洛阳", label: "洛阳" },
        { value: "平顶山", label: "平顶山" },
        { value: "安阳", label: "安阳" },
        { value: "鹤壁", label: "鹤壁" },
        { value: "新乡", label: "新乡" },
        { value: "焦作", label: "焦作" },
        { value: "濮阳", label: "濮阳" },
        { value: "许昌", label: "许昌" },
        { value: "漯河", label: "漯河" },
        { value: "三门峡", label: "三门峡" },
        { value: "南阳", label: "南阳" },
        { value: "商丘", label: "商丘" },
        { value: "信阳", label: "信阳" },
        { value: "周口", label: "周口" },
        { value: "驻马店", label: "驻马店" },
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      orgList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        memberOrgName: null,
        memberOrgType: 1,
        memberOrgManager: null,
        memberOrgSn: null,
        memberOrgTel: null,
        memberOrgUsername: null,
        memberOrgState: null,
        memberOrgSignState: null,
        memberOrgPassword: null,
        loginIp: null,
        loginDate: null,
        delFlag: null,
        isPro: null,
        userId: null,
        createByUserName: null,
        memberOrgPayTime: null,
        prop: null,
        avatar: null,
        address: null,
        createByUserId: null,
        city: null,
        isProxyOrg: 2,
        ascriptionOrgId: null,
        ascriptionUserId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
      // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listOrg(this.queryParams).then((response) => {
        this.orgList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        memberOrgName: null,
        memberOrgType: 1,
        memberOrgManager: null,
        memberOrgSn: null,
        memberOrgTel: null,
        memberOrgUsername: null,
        memberOrgState: null,
        memberOrgSignState: null,
        memberOrgPassword: null,
        loginIp: null,
        loginDate: null,
        delFlag: null,
        isPro: null,
        userId: null,
        createByUserName: null,
        memberOrgPayTime: null,
        prop: null,
        avatar: null,
        address: null,
        createByUserId: null,
        city: null,
        isProxyOrg: 2,
        ascriptionOrgId: null,
        ascriptionUserId: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加会员单位";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getOrg(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改会员单位";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            this.form.memberOrgType = 1;
            updateOrg(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            console.log(this.form);
            this.form.memberOrgType = 1;
            addOrg(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除会员单位编号为"' + ids + '"的数据项？')
        .then(function () {
          return delOrg(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/org/export",
        {
          ...this.queryParams,
        },
        `org_${new Date().getTime()}.xlsx`
      );
    },
    setProxyAccount(row) {
      const id = row.id || this.ids;
      this.$modal
        .confirm("是否确认该会员单位为特殊单位账号？")
        .then(function () {
          return grow(id);
          // delOrg(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("设置成功");
        })
        .catch(() => {});
    },
    openInputDig(row) {
      const id = row.id || this.ids;
      this.inputMemberSync = true;
    },
    inputMember(row) {
      console.log(row);
    },
    handleFilePondInit: function () {
      console.log("FilePond has initialized");

      // example of instance method call on pond reference
      this.$refs.pond.getFiles();
    },
    downModelFile() {
        downloadTemplate().then(response=>{
          this.download(response.msg)

        })


    },
    clickPayFee(row) {
      const ids = row.id || this.ids;
      console.log(ids);
      fee(ids).then((response) => {

        this.payOrgList=response.data.memberOrgs
        this.OrgPrice=response.data.price
      });
      this.payFeeDig = true;
    },

  },
};
</script>
<style scoped>
.el-icon-user-solid .el-icon-more {
  color: #e6a23c;
}
.downModel {
  height: 76px;
  box-sizing: border-box;
  position: relative;
  margin-bottom: 1em;
  font-size: 1rem;
  line-height: normal;
  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica,
    Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
  font-weight: 450;
  text-align: left;
  text-rendering: optimizeLegibility;
  direction: ltr;
  contain: layout style size;
  background-color: #f1f0ef;
  border-radius: 4px;
}
.downButton {
  right: 0;
  margin: 0;
  color: #4f4f4f;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 0;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.downText {
  color: #4f4f4f;
  justify-content: center;
  align-items: center;
  display: block;
  margin: 0;
  margin-top: 10px;
  padding: 0.5em;
  font-size: inherit;
  cursor: default;
  font-size: 1rem;
  font-weight: 400;
  text-align: center;
  line-height: 2;
}
</style>
